// 20200907 Miray Kas
// 20201238 Sarp Arda Coskun
// Date: 24 Nov 2006, Friday
import jpcap.packet.TCPPacket;

public class HttpPacket 
{
	private String destIP;
	private String srcIP;
	private int destPort;
	private int srcPort;
	private long seqNum;
	private long ackNum;
	private int dataLength;
	private boolean isPaired = false;
	private String folder_name = "";
	private int contentLengthLeft;
	private int ackNumRespond;
	private boolean respMetaAlreadyAdded = false;
	
	public  HttpPacket(TCPPacket packet,String f)
	{
		destIP = packet.dst_ip.toString().substring(1);
		srcIP = packet.src_ip.toString().substring(1);
		destPort = packet.dst_port;
		srcPort = packet.src_port;
		seqNum = packet.sequence;
		ackNum = packet.ack_num;
		dataLength = packet.data.length;
		folder_name = f;
		contentLengthLeft = 0;
		ackNumRespond = 0;
	}

	public int getContentLengthLeft() {
		return contentLengthLeft;
	}

	public void setContentLengthLeft(int contentLengthLeft) {
		this.contentLengthLeft = contentLengthLeft;
	}	
	public boolean isPaired() {
		return isPaired;
	}

	public void setPaired(boolean isMatched) {
		this.isPaired = isMatched;
	}

	public long getAckNum() 
	{
		return ackNum;
	}

	public void setAckNum(long ackNum) {
		this.ackNum = ackNum;
	}

	public int getDataLength() {
		return dataLength;
	}

	public void setDataLength(int dataLength) {
		this.dataLength = dataLength;
	}

	public String getDestIP() {
		return destIP;
	}

	public void setDestIP(String destIP) {
		this.destIP = destIP;
	}

	public int getDestPort() {
		return destPort;
	}

	public void setDestPort(int destPort) {
		this.destPort = destPort;
	}

	public long getSeqNum() {
		return seqNum;
	}

	public void setSeqNum(long seqNum) {
		this.seqNum = seqNum;
	}

	public String getSrcIP() {
		return srcIP;
	}

	public void setSrcIP(String srcIP) {
		this.srcIP = srcIP;
	}

	public int getSrcPort() {
		return srcPort;
	}

	public void setSrcPort(int srcPort) {
		this.srcPort = srcPort;
	}

	public boolean equal1(HttpPacket pack)
	{
		return (int)pack.ackNum == getAckNumRespond();
	}
	
	// Checks dest's, src's, port and ips. Checks the ack and seq numbers also.
	public boolean equal2(HttpPacket pack)
	{
//		System.out.println("ack num = " + pack.ackNum);
//		System.out.println("seq num = " + this.seqNum);
//		System.out.println("datalength= " + pack.getDataLength());		
		return (pack instanceof HttpPacket) && pack.ackNum - pack.getDataLength() <= getSeqNum()
			&& pack.srcIP.equals(this.destIP) && pack.srcPort == this.destPort
			&& pack.destIP.equals(this.srcIP) && pack.destPort == this.srcPort;
	}

	// Checks dest's, src's, port and ips.	
	public boolean equal3(HttpPacket pack)
	{
		return (pack instanceof HttpPacket) && pack.srcIP.equals(this.destIP) && pack.srcPort == this.destPort
			&& pack.destIP.equals(this.srcIP) && pack.destPort == this.srcPort;
	}
	public String getFolder_name() {
		return folder_name;
	}

	public void setFolder_name(String folder_name) {
		this.folder_name = folder_name;
	}

	public int getAckNumRespond() {
		return ackNumRespond;
	}

	public void setAckNumRespond(int ackNumRespond) {
		this.ackNumRespond = ackNumRespond;
	}

	public boolean isRespMetaAlreadyAdded() {
		// TODO Auto-generated method stub
		return respMetaAlreadyAdded;
	}

	public void setRespMetaAlreadyAdded(boolean respMetaAlreadyAdded) {
		// TODO Auto-generated method stub
		this.respMetaAlreadyAdded = respMetaAlreadyAdded;
	}
	
}
